#include <func.h>

#define MAX_PATH 1024

typedef struct train_s{
    char buf[4096];
    int dataLen;
} train_t;

int cdCMD(int netfd, const char* usrName, const char* pathName){
TODO:
    //等待实现CD功能
    ;
}

int mkdirCmd(int netfd, const char* usrName, const char* pathName) {
    train_t train;
    int ret;
    cdCMD(netfd, usrName, NULL);
    char absPath[MAX_PATH];
    if (pathName[0] == '.'){
        char *retc = realpath(pathName, absPath);
        if (retc == NULL){
            perror("realpath");
            return -1;
        }
        ret = mkdir(absPath, 0777);
    } else {
        ret = mkdir(pathName, 0777);
    }
    if (ret == -1) {
        sprintf(train.buf, "mkdir: cannot create directory ‘%s’: No such file or directory", pathName);
        train.dataLen = strlen(train.buf);
        send(netfd, &train, train.dataLen + 4, 0);
        return -1;
    }
    return 0;
}
